home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
2.2
/
Raindrop.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
5KB
|
220 lines
" NAME Raindrop
AUTHOR mdf@cs.man.ac.uk
FUNCTION impl of a popular Unix program
ST-VERSIONS 2.2
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1.1
DATE 22 Jan 1989
SUMMARY Raindrop
is Michael's implementation of a popular UNIX program.(2.2). MDF
"!
'From Smalltalk-80, version 2, of April 1, 1983 on 7 March 1987 at 5:48:18 pm'!
Object subclass: #Raindrop
instanceVariableNames: 'formbox ringdict ringsizes '
classVariableNames: ''
poolDictionaries: ''
category: 'Graphics-Games'!
!Raindrop methodsFor: 'displaying'!
centre: aPoint delayedForMilliseconds: aDelay
^self
centre: aPoint
delayedForMilliseconds: aDelay
mask: #gray!
centre: aPoint delayedForMilliseconds: aDelay mask: aMask
ringsizes do:
[:size |
(ringdict at: size)
displayOn: Display
at: aPoint - formbox center
clippingBox: Display boundingBox
rule: Form reverse
mask: (Form perform: aMask).
(Delay forMilliseconds: aDelay) wait.
(ringdict at: size)
displayOn: Display
at: aPoint - formbox center
clippingBox: Display boundingBox
rule: Form reverse
mask: (Form perform: aMask)]!
centre: aPoint delayedForSeconds: aDelay
^self
centre: aPoint
delayedForSeconds: aDelay
mask: #gray!
centre: aPoint delayedForSeconds: aDelay mask:aMask
ringsizes do:
[:size |
(ringdict at: size)
displayOn: Display
at: aPoint - formbox center
clippingBox: Display boundingBox
rule: Form reverse
mask: (Form perform: aMask).
(Delay forSeconds: aDelay) wait.
(ringdict at: size)
displayOn: Display
at: aPoint - formbox center
clippingBox: Display boundingBox
rule: Form reverse
mask: (Form perform: aMask) ]! !
!Raindrop methodsFor: 'private'!
formbox: aBox ringdict: aDict ringsizes: aCollection
formbox _ aBox.
ringdict _ aDict.
ringsizes _ aCollection! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
Raindrop class
instanceVariableNames: ''!
Raindrop class comment:
'This class is the class of all raindrops!!'!
!Raindrop class methodsFor: 'instance creation'!
new: anIncrement maxExtent: maxRadius
"define new raindrop with standard pen width and inner circle"
^self
new: anIncrement
maxExtent: maxRadius
penWidth: 2
minExtent: 10
mask: #gray!
new: anIncrement maxExtent: maxRadius penWidth: anInteger
"define new raindrop with standard inner circle radius"
^self
new: anIncrement
maxExtent: maxRadius
penWidth: anInteger
minExtent: 10
mask: #gray!
new: anIncrement maxExtent: maxRadius penWidth: anInteger minExtent: minRadius
"define new raindrop with standard inner circle radius"
^self
new: anIncrement
maxExtent: maxRadius
penWidth: anInteger
minExtent: minRadius
mask: #gray!
new: anIncrement maxExtent: maxRadius penWidth: anInteger minExtent: minRadius mask:aMask
"define new raindrop"
| radius circleForm rC rCForm ringdict ringsizes exPoint cPoint formbox |
ringdict _ Dictionary new.
ringsizes _ SortedCollection new.
rCForm _ Form new extent: anInteger @ anInteger.
rCForm perform: aMask.
radius _ minRadius.
rC _ Circle new.
rC form: rCForm.
cPoint _ Point new setX: maxRadius + 1 setY: maxRadius + 1.
exPoint _ Point new setX: 2 * maxRadius + 2 setY: 2 * maxRadius + 2.
rC center: cPoint.
[radius <= maxRadius]
whileTrue:
[rC radius: radius.
circleForm _ Form new extent: exPoint.
rC displayOn: circleForm.
ringsizes addLast: radius.
ringdict at: radius put: circleForm.
radius _ radius + anIncrement].
formbox _ circleForm boundingBox.
^self new
formbox: formbox
ringdict: ringdict
ringsizes: ringsizes! !
!Raindrop class methodsFor: 'examples'!
example
"Runs a rain example until a button is pressed (may even continue for
a while after that!!)"
| r exampleRain |
exampleRain _ Raindrop new: 50 maxExtent: 210.
r _ Random new.
[Sensor noButtonPressed]
whileTrue:
[[exampleRain
centre: r next * Display width @ (r next * Display height)
delayedForSeconds: 0.2] fork.
(Delay forSeconds: 0.1) wait
]
"Raindrop example"!
example2
"Runs a rain example until a button is pressed"
| r exampleRain |
exampleRain _ Raindrop
new: 50
maxExtent: 210
penWidth: 4.
r _ Random new.
[Sensor noButtonPressed]
whileTrue:
[[exampleRain centre: r next * Display width @ (r next * Display height) delayedForSeconds: 0.2 ] fork.
(Delay forSeconds: 0.1) wait
]
"Raindrop example2"!
example3
"Runs a rain example until a button is pressed"
| r exampleRain |
exampleRain _ Raindrop
new: 30
maxExtent: 210
penWidth: 4
minExtent: 15.
r _ Random new.
[Sensor noButtonPressed]
whileTrue:
[[exampleRain centre: r next * Display width @ (r next * Display height) delayedForSeconds: 0.2] fork.
(Delay forSeconds: 0.1) wait
]
"Raindrop example3"!
example4
"Runs a rain example until a button is pressed"
| r exampleRain |
Display white.
Cursor blank showWhile: [
exampleRain _ Raindrop
new: 20
maxExtent: 180
penWidth: 4
minExtent: 15
mask: #darkGray.
r _ Random new.
[Sensor noButtonPressed] whileTrue:
[[exampleRain centre: r next * Display width @
(r next * Display height) delayedForSeconds: 0.2] fork.
(Delay forSeconds: 0.1) wait
].
(Delay forSeconds: 3) wait].
ScheduledControllers restore.
"Raindrop example4"! !